package com.lishe.lishe.lishe.module.excitation.adapter;

import android.support.v7.widget.RecyclerView;
import android.support.v7.widget.RecyclerView.ViewHolder;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.lishe.lishe.R;
import com.lishe.lishe.lishe.module.excitation.bean.company.CompanyInfo;

import java.util.List;

/**
 * Created by shino on 2017/12/21.
 */

public class CompanySignOutAdapter extends RecyclerView.Adapter<CompanySignOutAdapter.CompanyHolder> {
    private List<CompanyInfo> companys;

    public CompanySignOutAdapter(List<CompanyInfo> companys) {
        this.companys = companys;
    }

    @Override
    public CompanyHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.item_company_sign_out, null);
        CompanyHolder holder = new CompanyHolder(view);
        return holder;
    }

    @Override
    public void onBindViewHolder(CompanyHolder holder, final int position) {
        final CompanyInfo company = companys.get(position);
        holder.company.setText(company.getComName());
        if (company.getStatus() == 1) {
            holder.imagview.setVisibility(View.VISIBLE);
//            holder.imagview.setImageResource(R.mipmap.authentication_icon);
        } else {
            holder.imagview.setVisibility(View.GONE);
        }
        holder.itemView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (itemClick != null) {
                    itemClick.onItemClick(position, company);
                }
            }
        });

    }

    @Override
    public int getItemCount() {
        return companys == null ? 0 : companys.size();
    }

    class CompanyHolder extends ViewHolder {
        TextView company;
        ImageView imagview;

        public CompanyHolder(View itemView) {
            super(itemView);
            company = itemView.findViewById(R.id.company);
            imagview = itemView.findViewById(R.id.authentication);
        }
    }

    /**
     * item点击事件
     */
    OnItemtClick itemClick;

    public interface OnItemtClick {
        void onItemClick(int position, Object object);
    }

    public void setOnItemClick(OnItemtClick itemClick) {
        this.itemClick = itemClick;
    }
}
